<?php
/**
 * 系統名稱: Lotto 系統
 * 檔案說明: 專案管理-修改
 * $Author$
 * $Id$
 *
 */
$intID = (int)$_data["ID"];
$arrG = getGambleDataByID($intID);
if($arrG === false){
	ErrMsgOutputHTML("Error", "", 1);
}elseif(sizeof($arrG) == 0 || $arrG["isEnd"] == 1){
	header("Location: ".basename($_SERVER["PHP_SELF"])."?op=List&GameDate=".$_data["GameDate"]);
	exit();
}

$isErr = true;
$Y = explode("-",$data["GameDate_x"]);
$H = explode(":",$data["GameTime_x"]);
$arrET = explode(":",$data["EndGameTime_x"]);
$arrETSN = explode(":",$data["EndGameTimeSN_x"]);
if(!checkdate($Y[1], $Y[2], $Y[0])){
	$GLOBALS["errormessage"] = $_strCompetition["DateError"];//"賽程日期格式錯誤！";
}elseif(!is_array($H) || sizeof($H) != 3 || $H[0] < 0 || $H[0] > 23 || $H[1] < 0 || $H[1] > 59){
	$GLOBALS["errormessage"] = $_strCompetition["TimeError"];//"賽程時間格式錯誤！";
}elseif(!is_array($arrET) || sizeof($arrET) != 3 || $arrET[0] < 0 || $arrET[0] > 23 || $arrET[1] < 0 || $arrET[1] > 59){
	$GLOBALS["errormessage"] = $_strCompetition["TimeError"];//"賽程時間格式錯誤！";
}elseif(!is_array($arrETSN) || sizeof($arrETSN) != 3 || $arrETSN[0] < 0 || $arrETSN[0] > 23 || $arrETSN[1] < 0 || $arrETSN[1] > 59){
	$GLOBALS["errormessage"] = $_strCompetition["TimeError"];//"賽程時間格式錯誤！";
}else{
	$isErr = false;
}

if($isErr){
	$GLOBALS["errorhidden"] = "\nLine: ".__LINE__.",\nPage: ".__FILE__;
	ErrMsgOutputHTML("Error", "", 1);
}

$data["SerialNo_x"] = (float)$data["SerialNo_n"];
$data["OSerialNo_x"] = (float)$data["OSerialNo_n"];
$data["PayupDate_x"] = $data["GameDate_x"];
$data["GameDate_x"] = DateForm($data["GameDate_x"], $data["GameTime_x"], "Y-m-d", "CToU");
$data["GameTime_x"] = TimeForm($data["GameDate_x"], $data["GameTime_x"], "H:i:s", "CToU");
$data["EndGameTime_x"] = TimeForm($data["GameDate_x"], $data["EndGameTime_x"], "H:i:s", "CToU");
$data["EndGameTimeSN_x"] = TimeForm($data["GameDate_x"], $data["EndGameTimeSN_x"], "H:i:s", "CToU");
print $data["SerialNo_n"]."==".$data["OSerialNo_n"];
if(!UpdateSQL($intID, $data, "`bet_Gamble`"))ErrMsgOutputHTML("Error", "", 1);

if($arrG["PayupDate"] != $data["PayupDate_x"]){
	PMA_mysql_query("BEGIN", $_ConnMaster);

	$strSQL = "update `bet_BetListTmp` set `PayupDate` = '".$data["PayupDate_x"]."' where GambleID = ".$intID;
	if(!PMA_mysql_query($strSQL, $_ConnMaster)){
		$GLOBALS["errormessage"] = "Change Wager Data Error!!";
		$GLOBALS["errorhidden"] = "Error: ".PMA_mysql_error($_ConnMaster)."\nLine:".__LINE__."\nPage:".__FILE__;
		PMA_mysql_query("ROLLBACK", $_ConnMaster);
		ErrMsgOutputHTML("Error", "", 1);
	}

	$strSQL = "update `bet_BetList` set `PayupDate` = '".$data["PayupDate_x"]."' where GambleID = ".$intID;
	if(!PMA_mysql_query($strSQL, $_ConnMaster)){
		$GLOBALS["errormessage"] = "Change Wager Data Error!!";
		$GLOBALS["errorhidden"] = "Error: ".PMA_mysql_error($_ConnMaster)."\nLine:".__LINE__."\nPage:".__FILE__;
		PMA_mysql_query("ROLLBACK", $_ConnMaster);
		ErrMsgOutputHTML("Error", "", 1);
	}
	PMA_mysql_query("COMMIT", $_ConnMaster);
}
if(!MakeGambleFile($_data["LottoID"]))ErrMsgOutputHTML("Error", "", 1);
@mysql_close($$_Conn);
header("Location: ".basename($_SERVER["PHP_SELF"])."?op=List&GameDate=".$_data["GameDate"]);
?>